variables:
  PIP_CACHE_DIR: "$CI_PROJECT_DIR/venv"

stages:
  - build
  - test

cache:
  paths:
    - $CI_PROJECT_DIR/venv
  key: $CI_PROJECT_ID

before_script:
  - python -V
  - export PIP_CACHE_DIR='$CI_PROJECT_DIR/venv/'
  - chmod +x -R venv && ls -a venv
  - cd $CI_PROJECT_DIR/venv && ls -a
  - python3 -m pip install --upgrade pip
  - pip install -r requirements.txt
  - cd ..
  


build-job: &builds
  stage: build
  cache:
    key: $CI_PROJECT_ID
    paths:
    - $CI_PROJECT_DIR/venv
  image: mcr.microsoft.com/playwright/python:v1.41.0-jammy
  script:
    - python3 -v

test-job1:
  <<: *builds
  stage: test
  cache:
    key: $CI_PROJECT_ID
    paths:
    - $CI_PROJECT_DIR/venv
  needs:  
    - build-job
  image: mcr.microsoft.com/playwright/python:v1.41.0-jammy
  script:
    - python3 -v
    - ls -a
    - pytest tests/test_main.py
  rules:
    - when: on_success  


test-job2:
  <<: *builds
  stage: test
  cache:
    key: $CI_PROJECT_ID
    paths:
    - $CI_PROJECT_DIR/venv
  needs: 
    - build-job
  image: mcr.microsoft.com/playwright/python:v1.41.0-jammy
  script:
    - python3 -v
  rules:
    - when: on_success 

deploy-prod:
  <<: *builds
  stage: test
  cache:
    key: $CI_PROJECT_ID
    paths:
    - $CI_PROJECT_DIR/venv
  needs: 
    - test-job1
  variables:
    PROJECT_NAME: $CI_PROJECT_NAME
  image: mcr.microsoft.com/playwright/python:v1.41.0-jammy
  script:
    - python3 -v
  rules:
    - when: on_success 
